﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KeRui.BLL;
using KeRui.Common;
using System.Text;

public partial class Manage_Cms_AjaxRequest : System.Web.UI.Page
{
    private readonly string _act = PageRequest.GetString("act");
    protected void Page_Load(object sender, EventArgs e)
    {
        KeRui.BLL.CmsContent bllCmsContent = new CmsContent();
        switch (_act)
        {
            case "content_top":
                if (bllCmsContent.UpdateFourStatus(PageRequest.GetInt("contentid", -1), "IsTop") == 1)
                    Response.Write("置顶");
                else
                    Response.Write("取消置顶");
                Response.End();
                break;
            case "content_hot":
                if (bllCmsContent.UpdateFourStatus(PageRequest.GetInt("contentid", -1), "IsHot") == 1)
                    Response.Write("热点");
                else
                    Response.Write("取消热点");
                Response.End();
                break;
            case "content_marked":
                if (bllCmsContent.UpdateFourStatus(PageRequest.GetInt("contentid", -1), "IsMarked") == 1)
                    Response.Write("醒目");
                else
                    Response.Write("取消醒目");
                Response.End();
                break;
            case "content_recommend":
                if (bllCmsContent.UpdateFourStatus(PageRequest.GetInt("contentid", -1), "IsRecommend") == 1)
                    Response.Write("推荐");
                else
                    Response.Write("取消推荐");
                Response.End();
                break;
            case "gettalefields":
                KeRui.BLL.TagModule bllTagModule = new TagModule();
                DataTable dt = bllTagModule.GetFieldsByTableID(PageRequest.GetInt("tableid", -1));
                StringBuilder sb = new StringBuilder();
                foreach (DataRow row in dt.Rows)
                {
                    sb.AppendFormat("<option value='{0}'>{0}-{1}</option>", row["name"], row["value"]);
                }
                Response.Write(sb.ToString());
                Response.End();
                break;
            case "genertagcode":
                string name = PageRequest.GetString("name");
                int tableid = PageRequest.GetInt("tableid", -1);
                string top = PageRequest.GetString("top");
                int id = PageRequest.GetInt("id", -1);
                string where = PageRequest.GetString("where");
                string order = PageRequest.GetString("order");
                string direction = PageRequest.GetString("direction");
                KeRui.BLL.TagModule bllTagModule1 = new TagModule();
                string tablename = bllTagModule1.GetTableNameByTableID(tableid);
                string code = string.Format("parameter_table_{0}_top_{1}_where_{2}_order_{3}_direction_{4}", tablename, top, where, order, direction);
                //存储
                KeRui.Model.TagModule modelTagModule = new KeRui.Model.TagModule();
                modelTagModule.ModuleName = name;
                modelTagModule.TopNum = PageRequest.GetInt("top", 0);
                modelTagModule.StrWhere = where;
                modelTagModule.OrderBy = order;
                modelTagModule.Direction = direction;
                modelTagModule.DataTable = tablename;
                modelTagModule.Code = code;
                string doaction = PageRequest.GetString("do");
                if (doaction == string.Empty)
                {
                    bllTagModule1.Add(modelTagModule);
                }
                else if (doaction == "modify")
                {
                    modelTagModule.ModuleID = id;
                    bllTagModule1.Update(modelTagModule);
                }
                Response.Write("parameter_" + name);
                Response.End();
                break;
            case "getkeywords":
                string title = PageRequest.GetString("title");
                title = KeRui.Common.SegmentHelper.GetKeyword(title);
                Response.Write(title);
                Response.End();
                break;
        }
    }
}
